import React from 'react';
import {formatMessage} from './intl';
import PropTypes from 'prop-types';
import {Button} from 'antd';
import ExcelImportIntl from '../common/ExcelImportIntl';
import {importDealerTemp} from './api';
import routes from './routes';

const basePath = fetch.basePath || '';

const description = [
    formatMessage({
        id: 'calendarImport.step2.description1',
        defaultMessage: '服务站编号、品牌编号、贸易方式 不能为空；'
    }),
    formatMessage({
        id: 'calendarImport.step2.description2',
        defaultMessage: '送达方、CBU间隔月份、KD间隔月份 不能为空；'
    }),
    formatMessage({
        id: 'calendarImport.step2.description3',
        defaultMessage: '备件超授权额度、币种、工时单价 不能为空；'
    }),
    formatMessage({
        id: 'calendarImport.step2.description5',
        defaultMessage: '索赔材料价格系数、备件管理费率 不能为空；'
    })
];

class DealerOrderSubmitRule extends React.PureComponent {
    constructor(props) {
        super(props);
        this.state = {loading: false};
    }

    afterUpload = file => {
        if(file.ok)
            this.props.onImportChange(true);
    }
    onChange = () => this.setState({loading: !this.state.loading});

    onReturn = () => this.props.history.push(routes.query.url());

    render() {
        return ([
            <div key="return" className="page-toolbar">
                <Button type="primary" onClick={this.onReturn} disabled={this.state.loading}>
                    {formatMessage({
                        id: 'fileImport.btm.back',
                        defaultMessage: '返回'
                    })}
                </Button>
            </div>,
            <ExcelImportIntl
                key="import"
                action={`${basePath}/afterSales/api/v1/dealerServiceInformations/import`}
                template={importDealerTemp}
                description={description}
                templateName={formatMessage({
                    id: 'import.show.importPart',
                    defaultMessage: '批量修改分类标准导入模板'
                })}
                beforeUpload={this.onChange}
                afterUpload={this.onChange}/>
        ]);
    }
}
DealerOrderSubmitRule.propTypes = {
    onImportChange: PropTypes.func.isRequired,
    history: PropTypes.object
};
export default DealerOrderSubmitRule;
